﻿@namespace Masa.Blazor
@using Masa.Blazor.Extensions
@inherits MasaComponentBase

<CascadingValue Value="this" IsFixed>
    <div tabindex="@(Editable ? 0 : -1)"
         class="@GetClass()"
         style="@GetStyle()"
         ripple="@Editable"
         id="@Id"
         @ref="@Ref"
         @onclick="HandleOnClick"
         @onkeydown="HandleOnKeyDown">
        @GenStep()
        @GenLabel()
    </div>
</CascadingValue>

@code {

    private RenderFragment GenStep() => __builder =>
    {
        <span class="@_block.Element("step").AppendClasses(CssClassUtils.GetBackgroundColor(Color, !HasError && (Complete || _isActive)))">
            @GenStepContent()
        </span>
    };

    private RenderFragment GenStepContent() => __builder =>
    {
        if (HasError)
        {
            <MIcon>@ErrorIcon</MIcon>
        }
        else if (Complete)
        {
            if (Editable)
            {
                <MIcon>@EditIcon</MIcon>
            }
            else
            {
                <MIcon>@CompleteIcon</MIcon>
            }
        }
        else
        {
            @Step
        }
    };

    private RenderFragment GenLabel() => __builder =>
    {
        <div class="@_block.Element("label")">
            @ChildContent
        </div>
    };

}